package user.infrastructure.repository;

import user.domain.model.User;
import user.domain.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public class UserRepositoryImpl implements UserRepository {

    private final JpaUserRepository jpaRepo;

    @Autowired
    public UserRepositoryImpl(JpaUserRepository jpaRepo) {
        this.jpaRepo = jpaRepo;
    }

    @Override
    public User save(User user) {
        return jpaRepo.save(user);
    }

    @Override
    public void deleteById(Long userId) {
        jpaRepo.deleteById(userId);
    }

    @Override
    public Optional<User> findById(Long userId) {
        return jpaRepo.findById(userId);
    }

    @Override
    public Optional<User> findByUsername(String username) {
        return jpaRepo.findByUsername(username);
    }

    @Override
    public Optional<User> findByEmail(String email) {
        return jpaRepo.findByEmail(email);
    }

    @Override
    public List<User> findAll() {
        return jpaRepo.findAll();
    }
}
